﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

class Offset
{
   public enum MOVE_TYPE
   {
        TYPE_REL = 0,
        TYPE_REL_PARENT,
        TYPE_ABS,
        TYPE_ABS_PARENT
    }

    private String m_ParentObjectName;
    public System.String ParentObjectName
    {
        get { return m_ParentObjectName; }
        set { m_ParentObjectName = value; }
    }
    private Vector3  m_Axis;
    public Vector3 Axis
    {
        get { return m_Axis; }
        set { m_Axis = value; }
    }

    private float m_fDis;
    public float Dis
    {
        get { return m_fDis; }
        set { m_fDis = value; }
    }

    private MOVE_TYPE m_movType;
    public Offset.MOVE_TYPE MovType
    {
        get { return m_movType; }
        set { m_movType = value; }
    }

    public void Read(ref StreamLoadData fp)
    {
        fp.Read(ref m_ParentObjectName);
        fp.Read(ref m_Axis.x);
        fp.Read(ref m_Axis.y);
        fp.Read(ref m_Axis.z);
        fp.Read(ref m_fDis);
        int iType = 0;
        fp.Read(ref iType);
        m_movType = (MOVE_TYPE)iType;
    }
}

class Rotate
{
    public enum ROTATE_TYPE
    {
        TYPE_REL = 0,
        TYPE_REL_PARENT,
        TYPE_ABS,
        TYPE_ABS_PARENT
    }
    private ROTATE_TYPE m_rotType;
    public Rotate.ROTATE_TYPE RotType
    {
        get { return m_rotType; }
        set { m_rotType = value; }
    }

    private String m_ParentObjectName;
    public System.String ParentObjectName
    {
        get { return m_ParentObjectName; }
        set { m_ParentObjectName = value; }
    }

    private Vector3 m_Axis;
    public Vector3 Axis
    {
        get { return m_Axis; }
        set { m_Axis = value; }
    }
    private Vector3 m_PntAxisOrign;
    public UnityEngine.Vector3 PntAxisOrign
    {
        get { return m_PntAxisOrign; }
        set { m_PntAxisOrign = value; }
    }

    private float m_fAngle;
    public float Angle
    {
        get { return m_fAngle; }
        set { m_fAngle = value; }
    }
    public void Read(ref StreamLoadData fp)
    {
        fp.Read(ref m_ParentObjectName);

        fp.Read(ref m_PntAxisOrign.x);
        fp.Read(ref m_PntAxisOrign.y);
        fp.Read(ref m_PntAxisOrign.z);

        fp.Read(ref m_Axis.x);
        fp.Read(ref m_Axis.y);
        fp.Read(ref m_Axis.z);

        fp.Read(ref m_fAngle);
        int iType = 0;
        fp.Read(ref iType);
        m_rotType = (ROTATE_TYPE)iType;
    }
}

class TranFormData
{
    float[] m_fAngle = new float[3];
    public float[] Angle
    {
        get { return m_fAngle; }
        set { m_fAngle = value; }
    }
    float[] m_fTranlate = new float[3];
    public float[] Tranlate
    {
        get { return m_fTranlate; }
        set { m_fTranlate = value; }
    }
    float[] m_fScale = new float[3];
    public float[] Scale
    {
        get { return m_fScale; }
        set { m_fScale = value; }
    }
    public void Read(ref StreamLoadData fp)
    {
       
        for(int i=0; i<3; ++i)
        {
            fp.Read(ref m_fAngle[i]);
        }
        for (int i = 0; i < 3; ++i)
        {
            fp.Read(ref m_fTranlate[i]);
        }
        for (int i = 0; i < 3; ++i)
        {
            fp.Read(ref m_fScale[i]);
        }
    }
}
class MeshData
{
    private Vector3[] m_MeshPoint;
    public Vector3[] MeshPoint
    {
        get { return m_MeshPoint; }
        set { m_MeshPoint = value; }
    }

    private Vector2[] m_uv;
    public Vector2[] uv
    {
        get { return m_uv; }
        set { m_uv = value; }
    }
    private int[] m_TriangleIndex;
    public int[] TriangleIndex
    {
        get { return m_TriangleIndex; }
        set { m_TriangleIndex = value; }
    }

    public void Read(ref StreamLoadData fp)
    {
        int iPntNum = 0;
        fp.Read(ref iPntNum);
        m_MeshPoint = new Vector3[iPntNum];
        for (int i = 0; i< iPntNum; ++i)
        {
            fp.Read(ref m_MeshPoint[i].x);
            fp.Read(ref m_MeshPoint[i].y);
            fp.Read(ref m_MeshPoint[i].z);
        }

        int iUVNum = 0;
        fp.Read(ref iUVNum);
        if(iUVNum == iPntNum)
        {
            m_uv = new Vector2[iUVNum];
            for (int i = 0; i < iUVNum; ++i)
            {
                fp.Read(ref m_uv[i].x);
                fp.Read(ref m_uv[i].y);
            }
        }

        int iTriInxNum = 0;
        fp.Read(ref iTriInxNum);
        if(iTriInxNum > 0)
        {
            m_TriangleIndex = new int[iTriInxNum];
            for (int i = 0; i < iTriInxNum; ++i)
            {
                fp.Read(ref m_TriangleIndex[i]);
            }

        }

    }
}

